package org.gten.gegedexin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.gten.gegedexin.Data.Mail;
import org.gten.gegedexin.pojo.MailInfoPojo;

import java.util.List;

/**
 * @author Eric
 * @date 2023/6/10
 */
@Mapper
public interface MailInfoDao extends BaseMapper<MailInfoPojo> {
    @Select("SELECT MAX(mail_id) FROM mail_info")
    Integer getValidInfoId();

    @Select("SELECT * FROM mail_info WHERE mail_id = #{mailId}")
    List<MailInfoPojo> getMailInfoById(int mailId);

    @Select("SELECT * FROM mail_info WHERE receiver = #{receiver}")
    List<MailInfoPojo> getMailInfoByReceiver(String receiver);

    @Select("SELECT * FROM mail_info WHERE sender = #{sender}")
    List<MailInfoPojo> getMailInfoBySender(String sender);

    @Select("SELECT * FROM mail_info WHERE sender = #{sender} AND date BETWEEN #{startTime} AND #{endTime}")
    List<MailInfoPojo> getRecentMailForSender(String sender, String startTime, String endTime);

    @Select("SELECT * FROM mail_info WHERE receiver = #{receiver} AND date BETWEEN #{startTime} AND #{endTime}")
    List<MailInfoPojo> getRecentMailForReceiver(String receiver, String startTime, String endTime);
}

